package com.starlinkdt.api.controller.admin.system;

import com.starlinkdt.common.annotation.Log;
import com.starlinkdt.common.core.controller.BaseController;
import com.starlinkdt.common.core.page.TableDataInfo;
import com.starlinkdt.common.domain.AjaxResult;
import com.starlinkdt.common.domain.system.dto.OaiServDto;
import com.starlinkdt.common.domain.system.entity.OaiServ;
import com.starlinkdt.common.enums.BusinessType;
import com.starlinkdt.common.utils.poi.ExcelUtil;
import com.starlinkdt.service.system.IOaiServService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * OAI服务Controller
 *
 * @author asset
 */
@Api(tags = "OAI服务管理")
@RestController
@RequestMapping("/admin/openapi/service")
public class OaiServController extends BaseController
{
    @Autowired
    private IOaiServService oaiServService;

    /**
     * 查询OAI服务列表
     */
    @ApiOperation("OAI服务-列表")
    @PreAuthorize("@ss.hasPermi('openapi:service:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaiServ oaiServ)
    {
        startPage();
        List<OaiServ> list = oaiServService.selectOaiServList(oaiServ);
        return getDataTable(list);
    }

    /**
     * 导出OAI服务列表
     */
    @ApiOperation("OAI服务-导出")
    @PreAuthorize("@ss.hasPermi('openapi:service:export')")
    @Log(title = "OAI服务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaiServ oaiServ)
    {
        List<OaiServ> list = oaiServService.selectOaiServList(oaiServ);
        ExcelUtil<OaiServ> util = new ExcelUtil<OaiServ>(OaiServ.class);
        util.exportExcel(response, list, "OAI服务数据");
    }

    /**
     * 获取OAI服务详细信息
     */
    @ApiOperation("OAI服务-查询")
    @PreAuthorize("@ss.hasPermi('openapi:service:query')")
    @GetMapping(value = "/{servBizNo}")
    public AjaxResult getInfo(@PathVariable("servBizNo") String servBizNo)
    {
        return success(oaiServService.selectOaiServByServBizNo(servBizNo));
    }

    /**
     * 新增OAI服务
     */
    @ApiOperation("OAI服务-新增")
    @PreAuthorize("@ss.hasPermi('openapi:service:add')")
    @Log(title = "OAI服务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaiServDto oaiServDto)
    {
        return toAjax(oaiServService.insertOaiServ(oaiServDto));
    }

    /**
     * 修改OAI服务
     */
    @ApiOperation("OAI服务-修改")
    @PreAuthorize("@ss.hasPermi('openapi:service:edit')")
    @Log(title = "OAI服务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaiServDto oaiServDto)
    {
        return toAjax(oaiServService.updateOaiServByServBizNo(oaiServDto));
    }

    /**
     * 启用OAI服务
     */
    @ApiOperation("OAI服务-启用")
    @PreAuthorize("@ss.hasPermi('openapi:service:edit')")
    @Log(title = "OAI服务", businessType = BusinessType.UPDATE)
    @PutMapping("enable/{servBizNos}")
    public AjaxResult enable(@PathVariable String[] servBizNos)
    {
        return toAjax(oaiServService.enableOaiServByServBizNos(servBizNos));
    }

    /**
     * 禁用OAI服务
     */
    @ApiOperation("OAI服务-禁用")
    @PreAuthorize("@ss.hasPermi('openapi:service:edit')")
    @Log(title = "OAI服务", businessType = BusinessType.UPDATE)
    @PutMapping("disable/{servBizNos}")
    public AjaxResult disable(@PathVariable String[] servBizNos)
    {
        return toAjax(oaiServService.disableOaiServByServBizNos(servBizNos));
    }

    /**
     * 删除OAI服务
     */
    @ApiOperation("OAI服务-删除")
    @PreAuthorize("@ss.hasPermi('openapi:service:remove')")
    @Log(title = "OAI服务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{servBizNos}")
    public AjaxResult remove(@PathVariable String[] servBizNos)
    {
        return toAjax(oaiServService.deleteOaiServByServBizNos(servBizNos));
    }

}
